package com.zhiyou.servlet.user;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zhiyou.service.UserService;
import com.zhiyou.serviceImpl.UserServiceImpl;

/**
 * Servlet implementation class UserDelServlet
 */
@WebServlet("/UserDelServlet")
public class UserDelServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String u_id = request.getParameter("u_id");
		int id = Integer.parseInt(u_id);
		UserService us = new UserServiceImpl();
		boolean flag = us.delete(id);
		if(flag){
			request.setAttribute("msg", "删除成功");
			request.getRequestDispatcher("/UserShowServlet?1=1").forward(request, response);	
		}else{
			request.setAttribute("msg", "删除失败");
			request.getRequestDispatcher("/UserShowServlet?1=1").forward(request, response);		
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
